import java.util.Arrays;
import java.util.Collections;

/**
 * Created by mauricio on 9/17/14.
 */
public class Triangle {
    private int length;

    public String symbol = "*";

    public Triangle(int length) {
        this.length = length;
    }

    public String getOne() {
        return symbol;
    }

    public String getHorizontalLine() {
       return this.getHorizontalLine(this.length);
    }

    public String getHorizontalLine(int length) {
        StringBuilder asterisks = new StringBuilder();
        for(int i = 0; i < length; i++) asterisks.append(getOne());
        return String.valueOf(asterisks);

    }

    public String getVerticalLine(int length) {
        StringBuilder asterisks = null;
        for(int i = 0; i < length; i++) asterisks.append(getOne() + "\n");
        return String.valueOf(asterisks).replaceFirst("\\s+$", "");

    }

    public String getRightTriangle(int length) {
        StringBuilder asterisks = new StringBuilder();
        for(int i = 1; i <= length; i++) asterisks.append(this.getHorizontalLine(i) + "\n");
        return String.valueOf(asterisks).replaceFirst("\\s+$", "");
    }

    public String getRightTriangle() {
        return this.getRightTriangle(this.length);
    }

    public String getIsosceles() {
        StringBuilder asterisks = new StringBuilder();
        for(int i = 1; i <= length; i++) {
            asterisks.append(this.with(" ").getHorizontalLine(length - i) + this.getHorizontalLine((i*2) -1) + "\n");
        }
        return String.valueOf(asterisks).replaceFirst("\\s+$", "");
    }

    public String getDiamond() {
        StringBuilder asterisks = new StringBuilder();
        asterisks.append(getIsosceles() + "\n" + reverse(getIsosceles(), 1) );
        return String.valueOf(asterisks).replaceFirst("\\s+$", "");
    }

    public String getDiamondWithName( String name) {
        String d = getDiamond();
        return d.replace(getHorizontalLine((this.length * 2) -1), name);
    }

    public static String reverse(String triangle, int start) {
        String[] reversed = triangle.split("\n");
        StringBuilder asterisks = new StringBuilder();
        for(int i = reversed.length -(1+start); i > -1 ; i--) {
            asterisks.append(reversed[i] + "\n");
        }
        return String.valueOf(asterisks).replaceFirst("\\s+$", "");
    }

    public static void draw(String triangle) {
        System.out.println(triangle);
    }

    public Triangle with(String symbol) {
        Triangle t = new Triangle(length);
        t.symbol = symbol;
        return t;
    }


    public static void main(String[] args) throws CloneNotSupportedException {
        Triangle triangle = new Triangle(3);

        draw(triangle.getOne());
        draw(triangle.getHorizontalLine());
        draw(triangle.getRightTriangle());
        //draw(reverse(triangle.getIsosceles()));
        draw(triangle.getIsosceles());
        draw(triangle.getDiamond());
        draw(triangle.getDiamondWithName("Bill"));

    }


}
